<!-- 奖品管理 -->
<template>
    <div class="rightCenter">
        <div class="listTop">
            <div class="listTopAddBut" @click="addClick()">
                新建奖品
            </div>
            <div class="listTopInpBox">
                <div class="listTopInpIco">
                    <i class="icon font_family icon-sousuo"></i>
                </div>
                <input class="listTopInp" type="text" v-model='searchVal' oninput='searchFun' placeholder="搜索活动名称">
            </div>
        </div>
        <ul class="listUl">
            <li class="listLi fristLI">
                <div class="listDiv listOne">
                    序号
                </div>
                <div class="listDiv listTwo">
                    奖品名称
                </div>
                <div class="listDiv listThree">
                    已发放
                </div>
                <div class="listDiv listFour">
                    业务主名称
                </div>
                <div class="listDiv listFive">
                    操作
                </div>
            </li>
            <li class="listLi dataLi" v-for="(item,index) in dataList" :class="{grayBack:index % 2 == 1}" :key='index'>
                <div class="listDiv listOne">
                    {{item.id | baseStrFun}}
                </div>
                <div class="listDiv listTwo">
                    {{item.name | baseStrFun}}
                </div>
                <div class="listDiv listThree">
                    {{item.used}}
                </div>
                <div class="listDiv listFour">
                    {{item.providerName | baseStrFun}}
                </div>
                <div class="listDiv listFive">
                    <div class="buttonBox audit" v-show='item.approval == "0" && item.permission % 7  == 0' @click='checkClick(index)'>
                        审核
                    </div>
                    <div class="buttonBox pass" v-show='item.approval == "1"'>
                        审核通过
                    </div>
                    <div class="buttonBox fail" v-show='item.approval == "2"'>
                        审核失败
                    </div>
                    <div class="buttonBox edit" v-show='item.permission % 3  == 0' @click='loogClick(index,2)'>
                        编辑
                    </div>
                </div>
            </li>
        </ul>
        <div class="paging">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNo" :page-sizes="[10, 20, 30, 40]"
                :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalVal">
            </el-pagination>
        </div>
        <!-- 审核弹框 -->
        <div class="fixedBox" v-show='checkShow'>
            <div class="popupCheckBox">
                <div class="popuplistBoxTop">
                    <div class="popuplistBoxTopFont">
                        请选择需要执行的操作
                    </div>
                    <div class="popuplistBoxTopBut" @click='checkCancelClick()'>
                        <i class="icon font_family icon-chuangkouguanbi-dianji"></i>
                    </div>
                </div>
                <div class="popupCheckButton">
                    <div class="popupCheckPass" @click='checkPassClick()'>
                        审核通过
                    </div>
                    <div class="popupCheckFail" @click='checkFailClick()'>
                        审核失败
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { mapActions } from "vuex";
import prizeRequest from "../../assets/prize";
export default {
  data() {
    return {
      searchVal: "", //搜索
      dataList: [],
      checkShow: false, //审核弹框
      checkIndex: "", //
      pageNo: 1, //页码
      pageSize: 10, //每页条数
      totalVal: 0 //总数量
    };
  },
  filters: {},
  created: function() {
    let self = this;
    if (sessionStorage.getItem("TABLIST")) {
      let arr = JSON.parse(sessionStorage.getItem("TABLIST"));
      let routShow = false;
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].name == "奖品管理") {
          routShow = true;
        }
      }
      if (!routShow) {
        this.$router.push({
          path: "/login"
        });
        sessionStorage.clear();
        self.$message("暂无权限");
        return;
      }
    }else{
       this.$router.push({
          path: "/login"
        });
        sessionStorage.clear();
        self.$message("暂无权限");
        return;
    }
    this.searchVal = "";
    this.searchFun();
  },
  watch: {
    searchVal(val) {
      this.searchFun(val);
    }
  },
  mounted() {},
  methods: {
    //分页 - 每页条数
    handleSizeChange(val) {
      this.pageSize = val;
      this.searchFun();
    },
    //分页 - 页数
    handleCurrentChange(val) {
      this.pageNo = val;
      this.searchFun();
    },
    //搜索
    async searchFun(name = "") {
      let self = this;
      let params = {
        name: self.searchVal,
        page: self.pageNo,
        size: self.pageSize
      };
      let getParams = `name=${params.name}&page=${params.page}&size=${
        params.size
      }`;
      let res = await prizeRequest.getWebAwardPage(getParams);
      if (res.statusCode == 200) {
        if (res.data) {
          if (res.data.records) {
            self.dataList = res.data.records;
          }
          self.totalVal = res.data.total * 1;
        }
      } else {
        self.$message(res.statusMessage);
        self.dataList = [];
      }
    },
    //添加
    addClick() {
      this.$router.push({
        path: "/home/prize/edit"
      });
    },
    //审核
    checkClick(index) {
      this.checkIndex = index;
      this.checkShow = true;
    },
    //审核通过
    async checkPassClick() {
      let self = this;
      this.checkShow = false;
      let params = {
        approval: 1,
        id: self.dataList[self.checkIndex].id
      };
      let res = await prizeRequest.getwebAwardupdateApproval(params);
      if (res.statusCode == 200) {
        self.$message("操作成功！");
        self.searchFun();
      } else {
        self.$message(res.statusMessage);
      }
    },
    //审核失败
    async checkFailClick() {
      let self = this;
      this.checkShow = false;
      this.checkShow = false;
      let params = {
        approval: 2,
        id: self.dataList[self.checkIndex].id
      };
      let res = await prizeRequest.getwebAwardupdateApproval(params);
      if (res.statusCode == 200) {
        self.$message("操作成功！");
        self.searchFun();
      } else {
        self.$message(res.statusMessage);
      }
    },
    //取消审核
    checkCancelClick() {
      this.checkShow = false;
    },
    //查看
    loogClick(index, val) {
      if (val == 2) {
        // 编辑
        this.$router.push({
          path: "/home/prize/editCompile?compile=compile"
        });
        sessionStorage.setItem(
          "prizeOBJ",
          JSON.stringify(this.dataList[index])
        );
      } else {
        // 查看
        // this.$router.push({
        //   path: "/home/prize/edit"
        // });
      }
    }
  }
};
</script>
<style scoped>
.listOne {
  width: 20%;
}

.listTwo {
  width: 20%;
}

.listThree {
  width: 20%;
}

.listFour {
  width: 20%;
}

.listFive {
  width: 20%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.audit {
  background: #f0a11f;
  margin-right: 4px;
}

.pass {
  color: #33ba78;
  margin-right: 4px;
  cursor: no-drop;
}

.fail {
  color: #ed4a47;
  margin-right: 4px;
  cursor: no-drop;
}

.look {
  background: #279de2;
  margin: 0 4px;
}

.edit {
  background: #279de2;
  margin: 0 4px;
}

.buleFont {
  color: #279de2;
}
</style>